Improve error reporting when source cannot be minimized #16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I ran into this
ValueError
while working on https://github.com/astral-sh/ruff/blob/main/scripts/fuzz-parser/fuzz.py, and found it slightly confusing at first. The issue we were running into was that a race condition (from running many fuzzing processes in parallel in aProcessPoolExecutor
) was meaning that ourcontains_bug()
function was flaky -- sopysource-codegen
would report that there was a bug, but thenpysource-minimize
wouldn't be able to repro the bug, causing the ValueError to be raised. But the exception message made me think that ruff's parser was erroring out because of some odd whitespace or other trivia that would be erased from theast.parse()
/ast.unparse()
roundtrip, and that wasn't the case.This PR attempts to improve the error message here slightly. It also adds a dedicated exception class, so that I can do
except CouldNotMinimize
here instead ofexcept ValueError
(which feels not great, since a lot of things could raiseValueError
; it's hard to know that theValueError
is coming frompysource-minimize
specifically there :-)